# Contributor: Thomas Kienlen <kommander@laposte.net>
# Contributor: Maxim Karasev <begs@disroot.org>
# Maintainer: Thomas Kienlen <kommander@laposte.net>
pkgname=freeciv
pkgver=3.0.2
pkgrel=1
pkgdesc="Free and Open Source empire-building strategy game (meta package)"
url="http://www.freeciv.org"
arch="all"
license="GPL-2.0-or-later"
depends="
	$pkgname-server
	$pkgname-client-gtk3
	"
_common_makedepends="
	curl-dev
	readline-dev
	gettext
	sdl2_mixer-dev
	gzip
	"
_gtk3_client_makedepends="
	pkgconf
	glib-dev
	at-spi2-core-dev
	pango-dev
	gdk-pixbuf-dev
	gtk+3.0-dev
	"
_qt_client_makedepends="
	qtchooser
	qt5-qtbase-dev
	gzip
	"
_sdl2_client_makedepends="
	sdl2-dev
	sdl2_image-dev
	sdl2_ttf-dev
	sdl2_gfx-dev
	"
_server_makedepends="
	sqlite-dev
	"
makedepends="
	$_common_makedepends
	$_gtk3_client_makedepends
	$_qt_client_makedepends
	$_sdl2_client_makedepends
	$_server_makedepends
	"
source="https://downloads.sourceforge.net/sourceforge/freeciv/freeciv-$pkgver.tar.xz"
subpackages="
	$pkgname-doc
	$pkgname-lang
	$pkgname-data::noarch
	$pkgname-server
	$pkgname-common-client:common_client:noarch
	$pkgname-client-gtk3:client_gtk3
	$pkgname-client-qt:client_qt
	$pkgname-client-sdl2:client_sdl2
	lib$pkgname-static:lib_static
	"

build() {
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-client=gtk3.22,qt,sdl2 \
		--enable-debug=no \
		--enable-fcmp=gtk3,qt,cli \
		--enable-fcdb=sqlite3 \
		--enable-ipv6=yes \
		--with-readline \
		--build=$CBUILD --host=$CHOST

	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

# subpackages

doc() {
	pkgdesc="Free and Open Source empire-building strategy game (documentation)"

	default_doc
}

data() {
	pkgdesc="Free and Open Source empire-building strategy game (data files for client and server)
	"
	depends=""
	mkdir -p "$subpkgdir/usr/share/freeciv"
	mv "$pkgdir/usr/share/freeciv" \
		"$subpkgdir/usr/share/"
}

lib_static() {
	pkgdesc="Free and Open Source empire-building strategy game (static libs for ai modules)
	"
	depends=""

	_files="
		usr/lib/libfreeciv-srv.a
		usr/lib/libfreeciv.a
		"

	for _file in $_files
	do
		_dest="$subpkgdir/$_file"
		mkdir -p "$(dirname $_dest)"
		mv "$pkgdir/$_file" \
			"$_dest"
	done
}

common_client() {
	pkgdesc="Free and Open Source empire-building strategy game (common files for every clients)"
	depends=""

	_files="
		usr/share/icons/hicolor/128x128/apps/freeciv-client.png
		usr/share/icons/hicolor/16x16/apps/freeciv-client.png
		usr/share/icons/hicolor/32x32/apps/freeciv-client.png
		usr/share/icons/hicolor/48x48/apps/freeciv-client.png
		usr/share/icons/hicolor/64x64/apps/freeciv-client.png
		usr/share/icons/hicolor/128x128/apps/freeciv-modpack.png
		usr/share/icons/hicolor/16x16/apps/freeciv-modpack.png
		usr/share/icons/hicolor/32x32/apps/freeciv-modpack.png
		usr/share/icons/hicolor/48x48/apps/freeciv-modpack.png
		usr/share/icons/hicolor/64x64/apps/freeciv-modpack.png

		usr/share/pixmaps/freeciv-client.png
		"

	for _file in $_files
	do
		_dest="$subpkgdir/$_file"
		mkdir -p "$(dirname $_dest)"
		mv "$pkgdir/$_file" \
			"$_dest"
	done
}

client_gtk3() {
	pkgdesc="Free and Open Source empire-building strategy game (gtk3.22 client)"
	depends="$pkgname-data $pkgname-common-client $pkgname-server"
	provides="$pkgname-client"
	provider_priority="1"

	_files="
		usr/bin/freeciv-gtk3.22
		usr/bin/freeciv-manual
		usr/bin/freeciv-mp-gtk3
		usr/share/applications/org.freeciv.gtk322.desktop
		usr/share/applications/org.freeciv.mp.gtk3.desktop
		usr/share/metainfo/org.freeciv.gtk322.appdata.xml
		usr/share/metainfo/org.freeciv.mp.gtk3.appdata.xml
		"

	for _file in $_files
	do
		_dest="$subpkgdir/$_file"
		mkdir -p "$(dirname $_dest)"
		mv "$pkgdir/$_file" \
			"$_dest"
	done
}

client_qt() {
	pkgdesc="Free and Open Source empire-building strategy game (qt client)"
	depends="$pkgname-data $pkgname-common-client $pkgname-server"
	provides="$pkgname-client"
	provider_priority="0"

	_files="
		usr/bin/freeciv-qt
		usr/bin/freeciv-mp-qt
		usr/bin/freeciv-ruledit
		usr/bin/freeciv-ruleup
		usr/share/applications/org.freeciv.mp.qt.desktop
		usr/share/applications/org.freeciv.qt.desktop
		usr/share/applications/org.freeciv.ruledit.desktop
		usr/share/metainfo/org.freeciv.mp.qt.appdata.xml
		usr/share/metainfo/org.freeciv.qt.appdata.xml
		usr/share/metainfo/org.freeciv.ruledit.appdata.xml
		usr/share/pixmaps/freeciv-modpack.png
		usr/share/pixmaps/freeciv-ruledit.png
		usr/share/icons/hicolor/128x128/apps/freeciv-ruledit.png
		usr/share/icons/hicolor/16x16/apps/freeciv-ruledit.png
		usr/share/icons/hicolor/32x32/apps/freeciv-ruledit.png
		usr/share/icons/hicolor/48x48/apps/freeciv-ruledit.png
		usr/share/icons/hicolor/64x64/apps/freeciv-ruledit.png
		"

	for _file in $_files
	do
		_dest="$subpkgdir/$_file"
		mkdir -p "$(dirname $_dest)"
		mv "$pkgdir/$_file" \
			"$_dest"
	done
}

client_sdl2() {
	pkgdesc="Free and Open Source empire-building strategy game (sdl2 client)"
	depends="$pkgname-data $pkgname-common-client $pkgname-server"
	provides="$pkgname-client"
	provider_priority="0"

	_files="
		usr/bin/freeciv-sdl2
		usr/share/applications/org.freeciv.sdl2.desktop
		usr/share/metainfo/org.freeciv.sdl2.appdata.xml
		"

	for _file in $_files
	do
		_dest="$subpkgdir/$_file"
		mkdir -p "$(dirname $_dest)"
		mv "$pkgdir/$_file" \
			"$_dest"
	done
}

server() {
	pkgdesc="Free and Open Source empire-building strategy game (server)"
	depends="$pkgname-data"

	mkdir -p "$subpkgdir/etc"
	mv "$pkgdir/etc/freeciv" \
		"$subpkgdir/etc/"

	_files="
		usr/bin/freeciv-server
		usr/bin/freeciv-mp-cli
		usr/share/applications/org.freeciv.server.desktop
		usr/share/metainfo/org.freeciv.server.appdata.xml
		usr/share/icons/hicolor/128x128/apps/freeciv-server.png
		usr/share/icons/hicolor/16x16/apps/freeciv-server.png
		usr/share/icons/hicolor/32x32/apps/freeciv-server.png
		usr/share/icons/hicolor/48x48/apps/freeciv-server.png
		usr/share/icons/hicolor/64x64/apps/freeciv-server.png
		"

	for _file in $_files
	do
		_dest="$subpkgdir/$_file"
		mkdir -p "$(dirname $_dest)"
		mv "$pkgdir/$_file" \
			"$_dest"
	done
}

sha512sums="
57373b5d3128ca5edd6140c76cf6b605d5cf6be3bf28063f9081d1fff08a3f7139971d04031372073fb6bfeface1a2e84fd8290940903d46104f5c1b18550a61  freeciv-3.0.2.tar.xz
"
